<template>
  <div class="home">
    <el-container>
      <el-aside style="width:auto" >
        <div class="logo">logo</div>
        <el-menu
          default-active=""
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          :collapse="isCollapse"
          :unique-opened='true'
          :router='true'
          active-text-color="#ffd04b">
          <el-submenu :index="first.id + ''" v-for="first in menusList" :key="first.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{first.authName}}</span>
            </template>
            <el-menu-item v-for="second in first.children" :key="second.id" :index="'/'+second.path">
              <i class="el-icon-menu"></i>
              <span>{{second.authName}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <span class="myicon myicon-menu toggle-btn" @click="clickbtn"></span>
          <span class="system-title">电商后台管理系统</span>
          <div><span class="welcome">你好，{{this.$store.getters.getUserName}}</span>  <button data-v-fae5bece="" type="button" class="el-button el-button--text" @click='loginOut'><span style="font-size:16px">退出</span></button></div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import {getLeftMenus} from '@/api/index.js'
export default {
  data () {
    return {
      isShow: true,
      isCollapse: false,
      menusList: []
    }
  },
  mounted () {
    getLeftMenus().then(res => {
      this.menusList = res.data
    })
  },
  methods: {
    loginOut () {
      // 删除token
      sessionStorage.removeItem('mytoken')
      // 跳转页面
      this.$router.push({path: 'login'})
    },
    clickbtn () {
      this.isCollapse = !this.isCollapse
    }
  }
}
</script>

<style lang="scss" scoped>
.home {
  height: 100%;
  .el-menu-admin:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
  .el-container {
    height: 100%;
  }
  .el-aside {
    background-color: #545c64;
  }
  .el-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #545c64;
  }
  .logo {
    height:60px;
    text-align: center;
    color: #fff;
    font-size: 20px;
    font-weight: bold;
    line-height: 60px;
    background-color: #999;
  }
  .toggle-btn {
    padding: 0 15px;
    margin-left: -20px;
    font-size: 36px;
    color: white;
    cursor: pointer;
    line-height: 60px;
    &:hover {
      background-color: #4292CF;
    }
  }
  .system-title {
    font-size: 28px;
    color: white;
  }
  .welcome {
    color: white;
    a{color: #4292CF;}
  }
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
}
</style>
